﻿using System;
using System.Windows.Forms;

namespace ALDIOrganizer
{
    public partial class ForWhom : Form
    {
        internal Int64 GetID;
        
        public ForWhom(string pCaption,
            Int64[] pIDs)            
        {
            InitializeComponent();
            Text = pCaption;
            SuspendLayout();

            
            lbEmployees.DataSource = NameIDPair.AsDataSource(pIDs);
            lbEmployees.DisplayMember = "Name";
            lbEmployees.ValueMember = "ID";

            if (lbEmployees.Items.Count > 0)
                lbEmployees.SelectedIndex = 0;
            ResumeLayout();

            lbEmployees.SelectedIndexChanged += lbEmployees_SelectedIndexChanged;
            btnOK.Click += (sender, e) => GetID = (Int64) lbEmployees.SelectedValue;
            ResumeLayout();
        }

        void lbEmployees_SelectedIndexChanged(object sender, EventArgs e)
        {
            btnOK.Enabled = (lbEmployees.SelectedIndex >= 0);
        }
    }
}
